package com.lijiajian.controller;

import com.lijiajian.Service.CustomerOrderService;
import com.lijiajian.Service.OrderDetailsService;
import com.lijiajian.base.BaseController;
import com.lijiajian.query.CustomerOrderQuery;
import com.lijiajian.query.CustomerQuery;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("customerOrder")
public class CustomerOrderController extends BaseController {
    @Resource
    private CustomerOrderService customerOrderService;
    @Resource
    private OrderDetailsService orderDetailsService;

    @GetMapping("customerOrderList")
    @ResponseBody
    public Map<String,Object> queryCustomerOrderByParams(CustomerOrderQuery customerOrderQuery){
        return customerOrderService.queryCustomerOrderByParams(customerOrderQuery);
    }

    @GetMapping("toOrderDetailPage")
    public String toOrderDetailPage(Integer id, HttpServletRequest request){
        if(id!=null){
            float orderSum=0;
            request.setAttribute("customerOrder",customerOrderService.selectByPrimaryKey(id));
            List<Float> sums = orderDetailsService.getSum(id);
            for(Float sum:sums){
                orderSum+=sum;
            }
            request.setAttribute("orderSum",orderSum);
        }
        return "customerOrder/orderDetail";
    }
}
